<template>
  <el-dialog
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    title="下发参数编辑"
    :append-to-body="true"
    :visible="stageVisible"
    width="40%"
    @close="close"
  >
    <el-table :data="formulaParameter" border stripe size="small">
      <el-table-column prop="stageId" label="阶段" align="center">
        <template slot-scope="scope"> 阶段{{ scope.$index + 1 }} </template>
      </el-table-column>
      <el-table-column prop="setTime" label="设定时间min" align="center">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.setTime"
            placeholder="请输入设定时间min"
            size="mini"
            clearable
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="setTemp" label="设定温度℃" align="center">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.setTemp"
            placeholder="请输入设定温度℃"
            size="mini"
            clearable
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="volumeTemp" label="温度公差℃" align="center">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.volumeTemp"
            placeholder="请输入温度公差℃"
            size="mini"
            clearable
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot="header">
          <div class="flex-x">
            <div style="margin-right: 10px">操作</div>
            <el-button type="primary" size="small" @click="addFormula"
              >添加</el-button
            >
          </div>
        </template>
        <template slot-scope="scope">
          <el-button type="danger" size="mini" @click="del(scope.$index)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <span slot="footer">
      <el-button
        type="primary"
        :loading="stageBtnloading"
        @click="submit"
        size="small"
        >{{ isIssued ? "确认下发" : "确认修改" }}</el-button
      >
      <el-button @click="close" size="small"> 取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getTaskDownLoadInfos } from "@/api/deviceOperation";
import { generateId } from "@/utils";
export default {
  props: {
    // 是否是下发按钮
    isIssued: {
      type: Boolean,
      default: false
    },
    stageVisible: {
      type: Boolean,
      default: false
    },
    stageBtnloading: {
      type: Boolean,
      default: false
    },
    formulaParameter: {
      type: Array,
      default: () => []
    }
  },
  // components:{
  //   formulaParameter
  // },

  data() {
    return {
      // formulaParameter: [],
    };
  },
  watch: {},
  mounted() {
    // 获取任务下发弹框列表
    // this.getTaskDownLoadInfos();
  },
  methods: {
    // 删除阶段
    del(index) {
      this.formulaParameter.splice(index, 1);
    },
    submit() {
      this.$emit("submit");
    },
    addFormula() {
      this.formulaParameter.push({
        setTime: "",
        setTemp: "",
        volumeTemp: "",
        id: generateId()
      });
    },
    close() {
      this.$emit("update:stageVisible", false);
    }
  }
};
</script>

<style></style>
